package cpr.command;

import cpr.DefaultCommandHandler;
import cpr.Printer;

public class CmdTestSleep extends DefaultCommandHandler {
	public CmdTestSleep() {
		super("sleep");
		setQuickInfo("for testing: sleeps for 10 sec ");
	}
	
	private int timer;
	public void execute(String[] params) {
		try {
			Printer.println("going to sleep");
			timer = 10;
			setProperty("timer", "10");
			while (timer>0) {
				Thread.currentThread().sleep(1000);
				timer --;
				setProperty("timer", ""+timer);
				Printer.println(""+timer+" seconds left...");
				yield();
			}
			Printer.println("done");
		} catch (Exception ex) {
			Printer.println("sleeper was interrupted!");
		}
	}

	public void yield() {
		applyExternalProps();
		timer = adjustIntProperty("timer",timer);
		
	}
}
